/*
 * @Description: 
 * @Version: 2.0
 * @Autor: ftt
 * @Date: 2022-06-11 09:35:09
 * @LastEditors: TT
 * @LastEditTime: 2022-06-22 15:59:30
 */

import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:hzy_normal_widget/hzy_normal_widget.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:lottie/lottie.dart';
import '../config/config_index.dart';

/// 创建加载动画
Widget createLoadWidget() {
  return LottieBuilder.asset(
    "assets/json/loading.json",
    width: 150.w,
    height: 150.w,
    alignment: Alignment.center,
  );
}

// 空数据动图
Widget createNoDataWidget() {
  return LottieBuilder.asset(
    "assets/json/empty.json",
    fit: BoxFit.contain,
    alignment: Alignment.center,
    width: 350.w,
    height: 350.w,
  );
}

/// 创建灰色阴影
BoxShadow configShadow() {
  return const BoxShadow(
    color: CommentColorS.cold9d9d9,
    offset: Offset(0, 3),
    blurRadius: 12.0,
    spreadRadius: 0,
  );
}

/// 创建绿色阴影
BoxShadow configgeryShadow() {
  return BoxShadow(
    color: CommentColorS.grey.withOpacity(0.6),
    blurRadius: 8.0,
  );
}

/// 创建主题色阴影
BoxShadow configThemeShadow() {
  return BoxShadow(
    color: HzyColorConfig().colthemes.withOpacity(0.8),
    offset: const Offset(0, 3),
    blurRadius: 10,
    spreadRadius: 0,
  );
}

/// 显示toast msg
/// 传content 后,如果没传ontap 会调用返回上一个界面的方法
/// type == 1 普通 toast , 2 成功toast 3 失败toast
void showtoastmsg(String msg,
    {int type = 1, BuildContext? context, Function()? ontap}) {
  EasyLoading.instance.loadingStyle = EasyLoadingStyle.dark;
  if (type == 1) {
    EasyLoading.showToast(msg);
  } else if (type == 2) {
    EasyLoading.showSuccess(msg);
  } else if (type == 3) {
    EasyLoading.showError(msg);
  }
  if (ontap != null || context != null) {
    Future.delayed(EasyLoading.instance.displayDuration).then((value) {
      if (ontap != null) {
        ontap();
      } else {
        Navigator.of(context!).pop();
      }
    });
  }
}
